/**
 * Created by liumin on 15-3-18.
 */

// 使用方法参见：https://github.com/felixge/node-mysql
var CONFIG = require('../../common/config');
var mysql = require('mysql');

exports.pool  = mysql.createPool({
    connectionLimit : 5,
    host            : CONFIG.DB_HOST_MYSQL,
    user            : CONFIG.DB_USER_MYSQL,
    password        : CONFIG.DB_PASSWORD_MYSQL,
    database        : CONFIG.DB_DATABASE_MYSQL,
    port            : CONFIG.DB_PORT_MYSQL
});

//pool.getConnection(function(err, connection) {
//    // Use the connection
//    connection.query('SELECT * FROM `books` WHERE `author` = ?', ['David'], function(err, rows) {
//        // And done with the connection.
//        connection.release();
//
//        // Don't use the connection here, it has been returned to the pool.
//    });
//});

//Preparing Queries
//
//You can use mysql.format to prepare a query with multiple insertion points, utilizing the proper escaping for ids and values. A simple example of this follows:
//
//      var sql = "SELECT * FROM ?? WHERE ?? = ?";
//      var inserts = ['users', 'id', userId];
//      sql = mysql.format(sql, inserts);


//connection.query('INSERT INTO posts SET ?', {title: 'test'}, function(err, result) {
//    if (err) throw err;
//
//    console.log(result.insertId);
//});